package com.example.yjhero.safeapp.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.yjhero.safeapp.R;
import com.example.yjhero.safeapp.utils.Myutils;
import com.example.yjhero.safeapp.utils.VersionUpdateUtils;

/**
     *
     * @author YJ HERO
     * 手机安全卫士
     *
     * */
public class SplasghActivity extends AppCompatActivity {
    String mVersion;
    Context mContext;
    TextView tv_splash_version;
    RelativeLayout relativeLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splasgh);
        mContext=this.getApplicationContext();
        ProgressDialog progressDialog=new ProgressDialog(mContext);
        mVersion=Myutils.getVersion(mContext);
        initView();
        initAnimation();
        VersionUpdateUtils versionUpdateUtils=new VersionUpdateUtils(this,mVersion);
        versionUpdateUtils.getCloudVersion();

    }
    /**
     * 动画的显示
     */
    private void initAnimation() {
        //创建动画   0.0f完全透明，1.0完全显示
        //1：渐变动画
        AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f,1.0f);
        alphaAnimation.setDuration(3000);//动画播放时间
        alphaAnimation.setFillAfter(true);//动画结束的状态

        //2：旋转动画
        RotateAnimation rotateAnimation=new RotateAnimation(0,360,
               //设置锚点
                Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        rotateAnimation.setDuration(3000);
        rotateAnimation.setFillAfter(true);

        //3：比例动画
        ScaleAnimation scaleAnimation=new ScaleAnimation(0.0f,1.0f,0.0f,1.0f,
                Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        scaleAnimation.setDuration(3000);
        scaleAnimation.setFillAfter(true);

        //创建动画集
        AnimationSet animationSet=new AnimationSet(true);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(rotateAnimation);
        animationSet.addAnimation(scaleAnimation);

        relativeLayout.startAnimation(animationSet);

        //动画写在XML中,translate代表平移动画,只用在里面数值属性
    }
/**
 * 界面组件的初始化
 * */
    private void initView() {
       tv_splash_version=findViewById(R.id.tv_splash_version);
       tv_splash_version.setText("版本号："+mVersion);
        relativeLayout=findViewById(R.id.rl_splash_root);
    }
}
